package com.sky.mapper;

import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.entity.SetmealDish;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    int insertdish(Dish dish);

    List<Dish> selectwithpage(DishPageQueryDTO queryDTO);
    @Select("select * from dish where id=#{id}")
    Dish selectbyid(Long id);
    @Delete("delete from dish where id=#{id}")
    int deletebyid(Long id);
    @Select("select * from setmeal_dish where dish_id=#{id}")
    SetmealDish setmealselectbyid(@Param("id") Long id);
    @Delete("DELETE from dish_flavor where dish_id=#{id}")
    int deleteflavorbyid(Long id);
    @Select("select * from dish_flavor where dish_id=#{id}")
    List<DishFlavor> selectflavorbyid(Long id);

    int updatedish(Dish dish);

    int insertflavor(@Param("dishflavors") List<DishFlavor> dishflavors);

    List<Dish> list(Dish dish);
    List<DishFlavor> getByDishId(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);

}
